Fix build scripts and panic=abort
authorAlex Crichton <alex@alexcrichton.com>
Mon, 23 May 2016 15:44:27 +0000 (08:44 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 23 May 2016 15:44:27 +0000 (08:44 -0700)
Build scripts were apparently always compiled with the "dev" profile rather than
the standard "match whatever the normal build was" profile, which meant that if
dev/release disagreed on panic=abort you'd get compile errors. Seems bad!

This commit fixes this by just having build scripts always compile with the same
profile as libraries (for now), as this was the original intention anyway.

Closes #2726

src/cargo/ops/cargo_rustc/context.rs
tests/test_cargo_compile_custom_build.rs

index 0c914b406936722763b8b38010cf3f945938855a..bd5a76ba7a5b93933470d08ea1806c4fe2d57766 100644 (file)
@@ -632,10 +632,10 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
         }
     }
 
-    pub fn build_script_profile(&self, _pkg: &PackageId) -> &'a Profile {
-        // TODO: should build scripts always be built with a dev
+    pub fn build_script_profile(&self, pkg: &PackageId) -> &'a Profile {
+        // TODO: should build scripts always be built with the same library
         //       profile? How is this controlled at the CLI layer?
-        &self.profiles.dev
+        self.lib_profile(pkg)
     }
 
     pub fn rustflags_args(&self, unit: &Unit) -> CargoResult<Vec<String>> {
index 8dcd4874a351a07af2bf473f5623aee789bc7b10..f2434f26badd604155e274b5faf4b78198094420 100644 (file)
@@ -1930,3 +1930,45 @@ test!(custom_target_dir {
     assert_that(p.cargo_process("build").arg("-v"),
                 execs().with_status(0));
 });
+
+test!(panic_abort_with_build_scripts {
+    if !::is_nightly() {
+        return
+    }
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.5.0"
+            authors = []
+
+            [profile.release]
+            panic = 'abort'
+
+            [dependencies]
+            a = { path = "a" }
+        "#)
+        .file("src/lib.rs", "extern crate a;")
+        .file("a/Cargo.toml", r#"
+            [project]
+            name = "a"
+            version = "0.5.0"
+            authors = []
+            build = "build.rs"
+
+            [build-dependencies]
+            b = { path = "../b" }
+        "#)
+        .file("a/src/lib.rs", "")
+        .file("a/build.rs", "extern crate b; fn main() {}")
+        .file("b/Cargo.toml", r#"
+            [project]
+            name = "b"
+            version = "0.5.0"
+            authors = []
+        "#)
+        .file("b/src/lib.rs", "");
+
+    assert_that(p.cargo_process("build").arg("-v").arg("--release"),
+                execs().with_status(0));
+});